<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/8/14
 * Time: 21:24
 */

namespace Home\Model;

use Think\Model;
class LuckyMoneyModel extends Model{
    public function queryluckyMoney($userId){
        return $this->where("user_ID=".$userId)->select();
    }
    public function sumAll($userId){
        $sqlGot="SELECT sum(number) AS got from t_lucky_money where isGot=true and user_ID=".$userId;
        $got=$this->query($sqlGot);
        $sqlUserd="SELECT sum(number) AS used from t_lucky_money where isGot=FALSE and user_ID=".$userId;
        $used=$this->query($sqlUserd);
        $result=(int)$got[0]['got']-(int)$used[0]['used'];
        return $result;

        //return $this->where("user_ID=".$userId." AND isGot=false")->select();
    }
    public function addLuckyMoney($data){
        return $this->add($data);
    }
    /*删除分享*/
    public function deleteLuckyMoney($id){
        return $this->where("ID=".$id)->delete();
    }
    public function queryAll(){
        return $this->select();
    }
    public function queryByUserId($userId){
        return $this->where("user_ID=".$userId)->select();
    }
    public function isGot($userId){
        return $this->where("user_ID=".$userId." AND isGot=true")->select();
    }
    public function isUsed($userId){
        return $this->where("user_ID=".$userId." AND isGot=false")->select();
    }
    public function update($data){
        return $this->where("ID=".$data['id'])->save($data);
    }
}